package com.ash.controller.advertisement;

import com.ash.domain.Advertisement;
import com.ash.domain.vo.AdvertisementVo;
import com.ash.service.advertisement.AdvertisementService;
import com.ash.util.JsonUtil;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/4/1 16:49
 * @file : project06.com.ash.controller.advertisement.advertisementController.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
@Controller
public class AdvertisementController {
    @Resource
    AdvertisementService advertisementService;
    @PostMapping("/admin/advertisement")
    @ResponseBody
    public Integer addAdvertisement(Advertisement advertisement){
        advertisement.setCreatedate(new Date());
        return advertisementService.add(advertisement);
    }
    @RequestMapping("/admin/advertisement/selectAll")
    @ResponseBody
    public String selectAll(@Nullable @RequestParam("rid")Integer rid, @RequestParam("page") Integer page, @RequestParam("limit") Integer limit){
        /*查询数据*/
        List<AdvertisementVo> advertisements = advertisementService.selectByRole(rid, page, limit);
        int count = advertisementService.dataCount(rid);
        return JsonUtil.getJsonList(count,advertisements);
    }
    @RequestMapping("/admin/advertisementEdit")
    public String advertisementEdit(){
        return "messageEdit";
    }
    @RequestMapping("/admin/advertisement/delete")
    public Integer delete(@RequestParam("aid") Integer aid){
        return advertisementService.delete(aid);
    }
    @RequestMapping("/admin/advertisement/deleteByIds")
    @ResponseBody
    public Integer deleteByIds(@RequestParam("ids") List<Integer> ids){
        return advertisementService.deleteByIds(ids);
    }
}
